//*****************************************************************************
//
// Lab7.c - user programs
// Jonathan Valvano, Feb 4, 2011, EE345M
// Alex Santos, Matt Villarrubia
//*****************************************************************************
// feel free to adjust these includes as needed
#include "..\inc/hw_types.h"
#include "..\driverlib/sysctl.h"
#include "..\driverlib/gpio.h"
#include "os.h"
#include "fifo.h"
#include "LM3SXXXX.H"
#include "motor.h"


_tFIFO Fifo;


void On(OS_TCB* this){
		SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
	GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_7);
	for(;;){
		GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_7, 0x80); //generate pulse
		OS_Sleep(this,7);
		GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_7, 0x00); //generate pulse
		OS_Sleep(this,7);	
	}
}

void Forever(OS_TCB* this){
	for(;;);
}

//*******************final user  DEMONTRATE THIS TO TA**********
int main(void){

	OS_Init();           // initialize, disable interrupts
  	Motor_Init();

	//********initialize communication channels
  	OS_MailBox_Init();
  	Fifo = FIFO_CreateFifo(32, sizeof(char));

	//*******attach background tasks***********

  	OS_AddThread(Forever,100,LOWEST_PRIORITY);

	OS_AddThread(Motor_Drive,100,LOW_PRIORITY);

	OS_Launch(1);
	
  
	return 0;             // this never executes
}
